package com.atguigu.gmall.common.config.exception;


import com.atguigu.gmall.common.execption.GmallException;
import com.atguigu.gmall.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandle {

    @ExceptionHandler(GmallException.class)
    public Result gmallExceptionHandle(GmallException e) {
        log.error("发生错误了，异常为{}",e.toString());
        e.printStackTrace();
        Result result = new Result();
        result.setCode(e.getCode());
        result.setMessage(e.getMessage());
        return result;
    }

    @ExceptionHandler(Exception.class)
    public Result exceptionHandle(Exception e) {
        log.error("发生错误了，异常为{}",e.toString());
        e.printStackTrace();
        Result result = new Result();
        result.setCode(201);
        result.setMessage(e.getMessage());
        return result;
    }






}
